#include <unistd.h>
#include "../log/log.hpp"
#include "../extend/extend.hpp"

int main()
{
    // 测试Util.hpp里面的函数
    //   std::cout << "时间: " << log::Util::Data::GetTime() << std::endl;

    // std::cout << log::Util::File::IsExist("./test.cc") << std::endl;
    // std::cout << log::Util::File::GetDictory("./home/zrb/107期/log/log.cc") << std::endl;
    // log::Util::File::Create_Dictory("./abc/ab/a");

    // 测试日志的等级函数
    //  std::cout << log::LogLevel::GetLevelString(log::LogLevel::Level::DEBUG) << std::endl;
    //  std::cout << log::LogLevel::GetLevelString(log::LogLevel::Level::INFO) << std::endl;
    //  std::cout << log::LogLevel::GetLevelString(log::LogLevel::Level::WARNING) << std::endl;
    //  std::cout << log::LogLevel::GetLevelString(log::LogLevel::Level::ERROR) << std::endl;
    //  std::cout << log::LogLevel::GetLevelString(log::LogLevel::Level::FATAL) << std::endl;
    //  std::cout << log::LogLevel::GetLevelString(log::LogLevel::Level::UNKNOWN) << std::endl;

    // 测试日志信息类
    // log::LogMessage logmessage("test.cc",10,"tcp连接成功",log::LogLevel::Level::DEBUG,"logger");
    // log::LogMessage logmessage("test.cc", 10, "tcp连接成功", log::LogLevel::Level::DEBUG, "logger");
    // std::cout << logmessage._ctime << " " << logmessage._FileName << " " << logmessage._Line << " " << log::LogLevel::GetLevelString(logmessage._level) << " " << logmessage._tid << " " << logmessage._LogMessage << std::endl;

    // //测试格式化输出
    // log::Format f;
    //  std::cout << f.format(logmessage) << std::endl;

    // 测试落地的不同方向
    //   std::string logs = f.format(logmessage);
    //   log::Sink::ptr StdoutSink = log::SinkFactory::CreateSink<log::Stdoutsink>();
    //   log::Sink::ptr FileSink = log::SinkFactory::CreateSink<log::FileSink>("./FileLog/FileSink.log");
    //   log::Sink::ptr RollFileSink = log::SinkFactory::CreateSink<log::RollSink>("./FileLog/RollSink",1024 * 1024);
    //   StdoutSink->log(logs.c_str(),logs.size());
    //   FileSink->log(logs.c_str(),logs.size());

    // int count = 0;
    // while(count < 500000)
    // {
    //     // std::string tmp = logs.c_str() + std::to_string(count++);
    //     RollFileSink->log(logs.c_str(),logs.size());
    //     ++count;
    // }

    // size_t cur_size = 0;
    // while(cur_size < 10 * 1024 * 1024)
    // {
    //     RollFileSink->log(logs.c_str(),logs.size());
    //     cur_size += logs.size();
    //     usleep(100);//休眠一下,不然由于打印的时间短,滚动文件新创建的文件名与原来文件名一样,相当于没有创建
    // }

    // 测试同步日志
    //  std::string LogName = "SYNC_LOGGER";
    //  log::Format::ptr format(new log::Format("[%d{%H:%M:%S}][%t][%p][%c][%f:%l] %m%n"));
    //  log::LogLevel::Level level = log::LogLevel::Level::DEBUG;
    //  log::Sink::ptr StdoutSink = log::SinkFactory::CreateSink<log::Stdoutsink>();
    //  log::Sink::ptr FileSink = log::SinkFactory::CreateSink<log::FileSink>("./FileLog/FileSink.log");
    //  log::Sink::ptr RollFileSink = log::SinkFactory::CreateSink<log::RollSink>("./FileLog/RollSink", 1024 * 1024);
    //  std::vector<log::Sink::ptr> Sinks = {StdoutSink, FileSink, RollFileSink};
    //  log::logger::ptr logger(new log::SyncLogger(LogName, format, level, Sinks));

    // logger->Debug(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Info(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Warning(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Error(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Fatal(__FILE__, __LINE__, "%s", "测试日志");

    // size_t cursize = 0;
    // while (cursize < 10 * 1024 * 1024)
    // {
    //     logger->Fatal(__FILE__, __LINE__, "%s", "测试日志");
    //     cursize += 17;
    // }

    // 引入建造者模式
    //  log::logger::BuliderLogger::ptr Builder(new log::LocalBuildLogger());//先建造类型
    //  Builder->BuilderLoggerName("SYNC_LOGGER");
    //  Builder->BuilderLevel(log::LogLevel::Level::DEBUG);
    //  Builder->BuilderFormat("[%d{%H:%M:%S}][%t][%p][%c][%f:%l] %m%n");
    //  Builder->BuilderSinks<log::Stdoutsink>();
    //  Builder->BuilderType(log::logger::Type::LOGGER_SYNCH);
    //  log::logger::ptr logger = Builder->Build();//开始建造日志器

    // logger->Debug(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Info(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Warning(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Error(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Fatal(__FILE__, __LINE__, "%s", "测试日志");

    // 观察构造对应的类型
    // log::logger::BuliderLogger::ptr Builder(new log::LocalBuildLogger()); // 先建造类型
    // Builder->BuilderLoggerName("SYNC_LOGGER");
    // log::logger::ptr logger = Builder->Build(); // 开始建造日志器

    // logger->Debug(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Info(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Warning(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Error(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Fatal(__FILE__, __LINE__, "%s", "测试日志");
    // size_t cursize = 0;
    // while (cursize < 10 * 1024 * 1024)
    // {
    //     logger->Fatal(__FILE__, __LINE__, "%s", "测试日志");
    //     cursize += 17;
    // }

    // log::logger::BuliderLogger::ptr Builder(new log::LocalBuildLogger()); // 先建造类型
    // Builder->BuilderLoggerName("SYNC_LOGGER");
    // Builder->BuilderSinks<log::Stdoutsink>();
    // Builder->BuilderSinks<log::FileSink>("./LogFile/FileSink");
    // Builder->BuilderSinks<log::RollSink>("./LogFile/", 1024 * 1024);
    // log::logger::ptr logger = Builder->Build(); // 开始建造日志器

    // logger->Debug(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Info(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Warning(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Error(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Fatal(__FILE__, __LINE__, "%s", "测试日志");
    // size_t cursize = 0;
    // while (cursize < 10 * 1024 * 1024)
    // {
    //     logger->Fatal(__FILE__, __LINE__, "%s", "测试日志");
    //     cursize += 17;
    // }

    // 测试文件缓冲区
    // std::string body = "这是一条测试文件缓冲区的字符串\n";
    // log::Buffer buffer;
    // std::cout << "可写大小" << buffer.WriteAble() << std::endl;
    // std::cout << "可读大小" << buffer.ReadAble() << std::endl;
    // std::cout << buffer.empty() << std::endl;
    // for(int i = 0; i < 20; ++i)
    // {
    //     buffer.push(body.c_str(),body.size());
    // }
    // std::cout << "可写大小" << buffer.WriteAble() << std::endl;
    // std::cout << "可读大小" << buffer.ReadAble() << std::endl;
    // std::cout << buffer.empty() << std::endl;

    // std::ofstream ofs("./tmp.log",std::ios::binary);
    // for(int i = 0; i < buffer.ReadAble(); ++i)
    // {
    //     ofs.write(buffer.begin(),1);
    //     buffer.pop(1);
    // }

    // 测试异步日志器安全模式
    //   log::logger::BuliderLogger::ptr Builder(new log::LocalBuildLogger()); // 先建造类型
    //   Builder->BuilderLoggerName("SYNC_LOGGER");
    //   Builder->BuilderType(log::logger::Type::LOGGER_ASYNCH);//异步
    //   Builder->BuilderFormat("[%c]%m%n");
    //   Builder->BuilderSinks<log::Stdoutsink>();
    //   Builder->BuilderSinks<log::FileSink>("./LogFile/FileSink");
    //   Builder->BuilderSinks<log::RollSink>("./LogFile/", 1024 * 1024);
    //   log::logger::ptr logger = Builder->Build(); // 开始建造日志器

    // logger->Debug(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Info(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Warning(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Error(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Fatal(__FILE__, __LINE__, "%s", "测试日志");
    // size_t cursize = 0;
    // while (cursize < 10 * 1024 * 1024)
    // {
    //     logger->Fatal(__FILE__, __LINE__, "%s", "测试日志");
    //     cursize += 18;
    // }

    // 测试异步日志器性能模式
    // log::logger::BuliderLogger::ptr Builder(new log::LocalBuildLogger()); // 先建造类型
    // Builder->BuilderLoggerName("SYNC_LOGGER");
    // //Builder->BuilderType(log::logger::Type::LOGGER_ASYNCH); // 异步
    // Builder->BuilderFormat("[%c]%m%n");
    // Builder->BuilderSinks<log::Stdoutsink>();
    // Builder->BuilderSinks<log::FileSink>("./LogFile/FileSink");
    // Builder->BuilderSinks<log::RollSink>("./LogFile/", 1024 * 1024);
    // Builder->Build_AsyncWorker_UnSafeType(); // 性能模式
    // log::logger::ptr logger = Builder->Build(); // 开始建造日志器

    // logger->Debug(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Info(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Warning(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Error(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Fatal(__FILE__, __LINE__, "%s", "测试日志");
    // size_t cursize = 0;
    // while (cursize < 10 * 1024 * 1024)
    // {
    //     logger->Fatal(__FILE__, __LINE__, "%s", "测试日志");
    //     cursize += 18;
    // }

    // 测试日志管理器里面的主日志器,该日志进行本地输出
    //  log::logger::ptr logger = log::loggermanager::GetInstance().root_logger();
    //  logger->Debug(__FILE__, __LINE__, "%s", "测试日志");
    //  logger->Info(__FILE__, __LINE__, "%s", "测试日志");
    //  logger->Warning(__FILE__, __LINE__, "%s", "测试日志");
    //  logger->Error(__FILE__, __LINE__, "%s", "测试日志");
    //  logger->Fatal(__FILE__, __LINE__, "%s", "测试日志");
    //  size_t cursize = 0;
    //  while (cursize < 10 * 1024 * 1024)
    //  {
    //      logger->Fatal(__FILE__, __LINE__, "%s", "测试日志");
    //      cursize += 18;
    //  }

    // 测试全局建造者
    // log::logger::BuliderLogger::ptr GlobalBuild(new log::GlobalBuildLogger());
    // GlobalBuild->BuilderLoggerName("Async_Logger");
    // GlobalBuild->BuilderFormat("[%c]%m%n");
    // GlobalBuild->BuilderSinks<log::Stdoutsink>();
    // GlobalBuild->BuilderSinks<log::FileSink>("./LogFile/FileSink");
    // GlobalBuild->BuilderSinks<log::RollSink>("./LogFile/", 1024 * 1024);
    // GlobalBuild->BuilderType(log::logger::Type::LOGGER_ASYNCH);
    // GlobalBuild->Build_AsyncWorker_UnSafeType();//安全模式
    // GlobalBuild->BuilderLevel(log::LogLevel::Level::DEBUG);
    // GlobalBuild->Build();
    // log::logger::ptr logger = log::loggermanager::GetInstance().GetLogger("Async_Logger");//自己创建的日志器
    // logger->Debug(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Info(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Warning(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Error(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Fatal(__FILE__, __LINE__, "%s", "测试日志");
    // size_t cursize = 0;
    // while (cursize < 10 * 1024 * 1024)
    // {
    //     logger->Fatal(__FILE__, __LINE__, "%s", "测试日志");
    //     cursize += 18;
    // }

    // 测试宏,全局接口函数设计(代理模式),注意不要使用"[%c][%p]%m%n", "测试日志 "等日志器的格式化输出,因为这里是传的是C库里面的格式化输出
    //  log::logger::ptr lp = log::loggermanager::GetInstance().root_logger();//日志器的输出格式应该在创建日志器的时候才使用,不然会出现段错误，难以查找
    //  lp->DEBUG("[%s]", "测试日志");
    //  lp->INFO("[%s]", "测试日志");
    //  lp->WARNING("[%s]", "测试日志");
    //  lp->ERROR("[%s]", "测试日志");
    //  lp->FATAL("[%s]", "测试日志");

    // LOG_DEBUG(lp, "[%s]", "测试日志");
    // LOG_INFO(lp, "[%s]", "测试日志");
    // LOG_WARNING(lp, "[%s]", "测试日志");
    // LOG_ERROR(lp, "[%s]", "测试日志");
    // LOG_FATAL(lp, "[%s]", "测试日志");

    // LOGD("[%s]", "测试日志");
    // LOGI("[%s]", "测试日志");
    // LOGW("[%s]", "测试日志");
    // LOGE("[%s]", "测试日志");
    // LOGF("[%s]", "测试日志");

    // 测试扩展落地方式
    // log::logger::BuliderLogger::ptr Builder(new log::LocalBuildLogger()); // 先建造类型
    // Builder->BuilderLoggerName("SYNC_LOGGER");
    // Builder->BuilderType(log::logger::Type::LOGGER_ASYNCH); // 异步
    // Builder->BuilderFormat("[%c]%m%n");
    // Builder->BuilderSinks<TimeRollSink>("./LogFile/",TimeGap::GAP_SECONDE);      // 以滚动时间文件作为输出
    // Builder->Build_AsyncWorker_UnSafeType();    // 性能模式
    // log::logger::ptr logger = Builder->Build(); // 开始建造日志器
    // logger->Debug(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Info(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Warning(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Error(__FILE__, __LINE__, "%s", "测试日志");
    // logger->Fatal(__FILE__, __LINE__, "%s", "测试日志");
    // size_t cursize = 0;
    // while (cursize < 10 * 1024 * 1024)
    // {
    //     logger->Fatal(__FILE__, __LINE__, "%s", "测试日志");
    //     cursize += 18;
    // }

    return 0;
}
